function clockon(bgclock){
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth();
	var date=now.getDate();
	var day=now.getDay();
	var hour=now.getHours();
	var minu=now.getMinutes();
	var sec=now.getSeconds();
	var week;
	month=month+1;
	if(month<10) month="0"+month;
	if(date<10) date="0"+date;
	if(hour<10) hour="0"+hour;
	if(minu<10) minu="0"+minu;
	if(sec<10) sec="0"+sec;
	var arr_week=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	week=arr_week[day];
	var time="";
	time=year+"/"+ month + "/"+date+" "+week+" "+hour+":"+minu+":"+sec;
	if(document.all){
		bgclock.innerHTML="<b>"+time+"</b>"
	}
	var timer=setTimeout("clockon(bgclock)",200);
} 

function uppage(page)
{
  	page.value = page.value-1;
}

function downpage(page)
{
  	page.value = page.value-(-1);
}

//addbook
function addbookdiv(e)
{
	e.style.display="block";
}

//divshow
function divshow(e)
{
	e.style.display="block";
}

function addbook(table,type)
{   
	var newTr = table.insertRow();
    newTr.style.background="white";
               
    var newTd0 = newTr.insertCell();
    var newTd1 = newTr.insertCell();
    if(type == 0)
    	var newTd2 = newTr.insertCell();
    var newTd3 = newTr.insertCell();
     
    var page1 = document.getElementById("page1");
    var total = document.getElementById("total");
    var page = document.getElementById("page");
	var size = document.getElementById("size");
	var delsize = document.getElementById("delsize");
	var information = document.getElementById("information");
	
	//bookinformation;
 	var BOOK_ISBN = document.getElementById("BOOK_ISBN");
    var INSTORE_NUM = document.getElementById("NUM");
    if(type == 0)
		var INSTORE_PRICE = document.getElementById("PRICE");
	
	size.value = size.value - -1;
	if(size.value%12==1)
		total.value = total.value - -1;
		
	//set row;
	
	newTr.id="book" + size.value + delsize.value;
	newTd0.id="BOOK_ISBNTD" + size.value + delsize.value;
	newTd0.name="BOOK_ISBNTD" + size.value + delsize.value;
	newTd0.className = 'list_data_number';
	newTd1.id="NUMTD" + size.value + delsize.value;
	newTd1.name="NUMTD" + size.value + delsize.value;
	newTd1.className = 'list_data_number';
	if(type == 0)
	{
		newTd2.id="PRICETD" + size.value + delsize.value;
		newTd2.name="PRICETD" + size.value + delsize.value;
		newTd2.className = 'list_data_number';
	}
	
	newTd0.innerHTML = BOOK_ISBN.value; 
	information.value = information.value + '+' + BOOK_ISBN.value;
    newTd1.innerHTML = INSTORE_NUM.value;
    information.value = information.value + '+' + INSTORE_NUM.value;
    if(type == 0)
    {
    	newTd2.innerHTML= INSTORE_PRICE.value;
    	information.value = information.value + '+' + INSTORE_PRICE.value;
    }
    newTd3.className = 'list_data_number';
    newTd3.innerHTML = '&nbsp;&nbsp;<a style="CURSOR:hand" onclick="delbook(' + newTr.id + ',' + type + ');">delete</a> ';
    
    if(((page1.value*12) >= size.value)&&(((page1.value-1)*12) < size.value));
    else
    	newTr.style.display="none";
	 
	(document.getElementById("add")).style.display = "none";
	 
}


function delbook(book,type)

{ 
	var index=book.rowIndex;
	(document.getElementById("addbooktable")).deleteRow(index);
	
	var table = document.getElementById("addbooktable");
	var page1 = document.getElementById("page1");
    var total = document.getElementById("total");
    var page = document.getElementById("page");
	var size = document.getElementById("size");
	var delsize = document.getElementById("delsize");
	var information = document.getElementById("information");
	information.value = "";
	
	size.value = size.value - 1;
	delsize.value = delsize.value - -1;
	for(var i = 1;i <= size.value;i++)
	{
		var j;
		if(type == 0)
			j = 3;
		else
			j = 2;
		for(p = 0;p < j;p++)
			information.value = information.value + "+" + table.rows [i].cells[p].innerHTML;
	}
	if(size.value%12==0)
		total.value = total.value - 1;
	if(((page1.value-1)*12 >= size.value))
	{
		if(page1.value!=1)
		{
			page1.value = page1.value -1;
			page.value = page.value -1;
		}
	}
	for(var i = 1;i <= table.rows.length;i++)
	{
		if(((page1.value*12) >= i)&&(((page1.value-1)*12) < i))
			(table.rows[i]).style.display = "block";
		else
			(table.rows[i]).style.display = "none";
	}
	
}

function up(table)
{
	var page1 = document.getElementById("page1");
	if(page1.value > 1)
	{
		page1.value = page1.value -1;
		var page = document.getElementById("page");
		page.value = page.value - 1;
		for(var i = 1;i <= table.rows.length;i++)
		{
			if(((page1.value*12) >= i)&&(((page1.value-1)*12) < i))
				(table.rows[i]).style.display = "block";
			else
				(table.rows[i]).style.display = "none";
		}
	}
}

function down(table)
{
	var page1 = document.getElementById("page1");
	var total = document.getElementById("total");
	if(page1.value < total.value)
	{
		page1.value = page1.value - -1;
		var page = document.getElementById("page");
		page.value = page.value - -1;
		for(var i = 1;i <= table.rows.length;i++)
		{
			if(((page1.value*12) >= i)&&(((page1.value-1)*12) < i))
				(table.rows[i]).style.display = "block";
			else
				(table.rows[i]).style.display = "none";
		}
	}
}

function go(table)
{
	var page = document.getElementById("page");
	var total = document.getElementById("total");
	if(page.value > total.value)
		page.value = total.value;
	if(page.value < 1)
		page.value = 1;
		

	var page1 = document.getElementById("page1");
	page1.value = page.value;
	for(var i = 1;i <= table.rows.length;i++)
	{
		if(((page1.value*12) >= i)&&(((page1.value-1)*12) < i))
			(table.rows[i]).style.display = "block";
		else
			(table.rows[i]).style.display = "none";
	}
}

function out(e)
{
	e.style.display="none";
}


function addcheck(size,table,type)   {
	var mark = 0;
	var i;
	var icon;
	for(i = 1; i <= size;i++)
	{
		icon = document.getElementById("addicon_" + i);
		if(icon.className != "right")
		{
			mark = 1;
			break;
		}
	}
	if(mark == 1)
	{
		alert("Information fill in errors!");
		return false;
	}
	addbook(table,type);
	return true;
	
}


///////////////////////////////////////
